import { createSlice } from "@reduxjs/toolkit";
export const user=createSlice({
  name:'user',
  initialState:{
    accessToken:localStorage.getItem('accessToken') || "",
    refreshToken:localStorage.getItem('refreshToken') || "",
    HeaderImg:localStorage.getItem('HeaderImg') || "",
    username:localStorage.getItem('username') || "",
    UserId:localStorage.getItem('UserId') || "",
    LoginOpen:false
  },
  reducers:{
    showModal:(state)=>{
      state.LoginOpen=true
    },
    loginOption:(state,action)=>{
      state.accessToken=action.payload.accessToken
      state.refreshToken=""
      state.HeaderImg=action.payload.HeaderImg
      state.username=action.payload.username
      state.UserId=action.payload.UserId
    },
    loginOut:(state)=>{
      state.accessToken=""
      state.refreshToken=""
      state.HeaderImg=""
      state.username=""
      state.UserId=""
      localStorage.clear()
    },
    handleCancel:(state)=>{
      state.LoginOpen=false
    },
    handleOk:(state)=>{
      state.LoginOpen=false
    },
  }
})


export const {showModal,handleCancel,handleOk,loginOption,loginOut} = user.actions

export default user.reducer